#include <stdlib.h>
#include <stdio.h>
#include <string.h>
//#include <libc.h>
#include "protocol.h"
#include "strtol.h"
#include "hd44780.h"

unsigned char *protocol_s;
unsigned char *protocol_frame;
unsigned char src, dst;

void protocol_sync(unsigned long time, unsigned long next_time) {
	cmd_t cmd;
	unsigned char buf[9];

	cmd = sync;
	buf[0] = cmd;
	buf[1] = time;
	buf[2] = time >> 8;
	buf[3] = time >> 16;
	buf[4] = time >> 24;
	buf[5] = next_time;
	buf[6] = next_time >> 8;
	buf[7] = next_time >> 16;
	buf[8] = next_time >> 24;
	encode_frame(37, 255, buf, 9);
}

void protocol_fade_in(unsigned long time) {
	cmd_t cmd;
	unsigned char buf[5];

	cmd = fade_in;
	buf[0] = cmd;
	buf[1] = time;
	buf[2] = time >> 8;
	buf[3] = time >> 16;
	buf[4] = time >> 24;
	encode_frame(37, 255, buf, 5);
}

void protocol_fade_out(unsigned long time) {
	cmd_t cmd;
	unsigned char buf[5];

	cmd = fade_out;
	buf[0] = cmd;
	buf[1] = time;
	buf[2] = time >> 8;
	buf[3] = time >> 16;
	buf[4] = time >> 24;
	encode_frame(37, 255, buf, 5);
}

void protocol_next_dias(unsigned long time) {
	cmd_t cmd;
	unsigned char buf[5];

	cmd = next_dias;
	buf[0] = cmd;
	buf[1] = time;
	buf[2] = time >> 8;
	buf[3] = time >> 16;
	buf[4] = time >> 24;
	encode_frame(37, 255, buf, 5);
}

void protocol_previous_dias(unsigned long time) {
	cmd_t cmd;
	unsigned char buf[5];

	cmd = previous_dias;
	buf[0] = cmd;
	buf[1] = time;
	buf[2] = time >> 8;
	buf[3] = time >> 16;
	buf[4] = time >> 24;
	encode_frame(37, 255, buf, 5);
}

